﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Newtonsoft.Json.Linq;

namespace AcfunUpload
{
    public partial class Divided : Form
    {
        string version = "0.0.1.0";
        public Divided()
        {
            InitializeComponent();
        }

        private void Divided_Load(object sender, EventArgs e)
        {
            lblPath.Tag = "";
            
             
            new Thread(new ThreadStart(chechVersion)).Start();
        }
        void chechVersion()
        {
            this.Enabled = false;
            changeStatus("正在检测新版本..请稍等");
            try
            { 
                /*string re = WebRequestHelper.http("https://boomfun.work/api/uploader/checkversion/version/" + version);
                JObject obj = JObject.Parse(re);
                if ((int)obj["error_code"] == 1)
                {
                    MessageBox.Show("有新版本");
                    System.Diagnostics.Process.Start((string)obj["url"]);
                    Application.Exit(); 
                }*/
            }
            catch
            {

            }
            changeStatus("未启动");
            Enabled = true;
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (txtDividedTime.Text == "") {
                MessageBox.Show("还没填写分割长度","提示");
                return;
            }
            if ((string)lblPath.Tag == "")
            {
                MessageBox.Show("还没选择文件", "提示");
                return;
            }
            new Thread(new ThreadStart(dividedThread)).Start();
        }

        void dividedThread()
        {
            DataSaving.d = this;
            DataSaving.pgb = pgb;
            int time = Convert.ToInt32(txtDividedTime.Text);
            string path = (string)lblPath.Tag;
            changeStatus("复制文件中...");
            string newPath = Video.copyFile(path);
            changeStatus("获取视频长度...");
            VideoTime vt = Video.getVideoTime(newPath);
            changeStatus("分段中...");
            Video.dividedVideo(newPath, vt, time);
            
        }
        public void changeStatus(string c)
        {
            lblStatus.Text = c;
        }
        private void btnSelectFile_Click(object sender, EventArgs e)
        {
            string file = odlgFile.FileName;
            odlgFile.ShowDialog();
            if (file != odlgFile.FileName)
            {
                file = odlgFile.FileName;
                lblPath.Text = "选择文件：" + odlgFile.SafeFileName;
                lblPath.Tag = odlgFile.FileName;
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("https://boomfun.work/page/about.html");
        }
    }
}
